package com.demo.thread_interrupt;

import java.util.concurrent.TimeUnit;

/**
 * @author shenguangyang
 */
public class InterruptExample02 {
    private static class MyThread1 extends Thread {
        @Override
        public void run() {
            while (!interrupted()) {
                try {
                    System.out.println("Thread run");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            System.out.println("Thread end");

        }
    }
    public static void main(String[] args) throws InterruptedException {
        Thread thread1 = new MyThread1();
        thread1.start();
        TimeUnit.MILLISECONDS.sleep(10);
        thread1.interrupt();
        System.out.println("Main run");
    }
}
